---
title: Characterization and Tissue Tropism of newly identified ifla-virus and negevirus
  in tsetse flies Glossina morsitans morsitans
author: Irene K. Meki, Hannah-Isadora Huditz, Anton Strunov, René van Vlugt, Henry
  M. Kariithi, Mohammadreza Rezapanah, Wolfgang J. Miller, Just M. Vlak, Monique M.
  van Oers, Adly M.M. Abd-Alla
date: "04/11/2021"
output: word_document
---

## set up the working directory and load needed pakages

```{r}
library(ggplot2)
library(lattice)
library(gcookbook)
library(ggfortify)
library(datasets)
library(MASS)
library(survival)
library(rmarkdown)
library(knitr)
library(coxme)
library(lme4)
library(nlme)
library(tidyverse)
library(gapminder)
library(rcompanion)
library(FSA)
library(stats)
library(RCA)
library(broom)
library(sp)
library(MuMIn)
library(ggpubr)
library(AICcmodavg)
library(car)
library(ggthemes)

```

## load the data and prepare it

```{r}
#====================================
#work with the average of the 3 technical reading
setwd("P:/Hannah/for_Review_meeting")

fig1 <- read.csv("organs_all_avg2.csv")

fig1
str(fig1)
#qpcr1$Normalized_log_SQ<-as.numeric(qpcr1$Normalized_log_SQ)
attach(fig1)
head(fig1)
qpcr=na.omit(fig1)

```

## Prepare fig 1 A and B

```{r}
#produce figure
summary(fig1)

#to produce figure 6A
figs6avg<-ggplot(fig1,aes(x=Tissue,y=Normalized, fill=Tissue)) +
  geom_boxplot() + geom_jitter(width=0.1,alpha=0.2) + 
  facet_grid(Sex~Virus) + ylim(0,80)
figs6avg

tiff("figs6avg1.tiff", width = 6, height = 6, units = 'in', res = 300)
plot(figs6avg+theme_tufte() + theme(axis.line = element_line(size = 1, colour = "black")) + theme(axis.text.x=element_blank(),axis.ticks.x=element_blank()) + theme(legend.title = element_text(face = "bold")) + theme(legend.text = element_text(face = "italic"))) + xlab(expression(bold("Tissues"))) + ylab(expression (paste (bold("Normalized  "), bold("density"))))
dev.off()

#To produce the supllementary figure 6B
figs6avg<-ggplot(fig1,aes(x=Tissue,y=Normalized, fill=Tissue)) +
  geom_boxplot() + geom_jitter(width=0.1,alpha=0.2) + 
  facet_grid(Sex~Virus) + ylim(0,5)
figs6avg

tiff("figs6avg1.tiff", width = 6, height = 6, units = 'in', res = 300)
plot(figs6avg+theme_tufte() + theme(axis.line = element_line(size = 1, colour = "black")) + theme(axis.text.x=element_blank(),axis.ticks.x=element_blank()) + theme(legend.title = element_text(face = "bold")) + theme(legend.text = element_text(face = "italic"))) + xlab(expression(bold("Tissues"))) + ylab(expression (paste (bold("Normalized  "), bold("density"))))
dev.off()

#difference between tiussue regardsles the virus or the sex
model1<-glm(Normalized ~ Tissue, data = fig1)
summary(model1)
Anova(model1)

```

## statistical analysis for Iflavirus

```{r}
#work with iflavirus alone

fig1ifla <- subset(fig1, Virus=="Iflavirus")
fig1ifla

#difference between tissue regardsless the sex for iflavirus
model1<-glm(Normalized ~ Tissue, data = fig1ifla)
summary(model1)
Anova(model1)

#difference between sex regardsless the tissues for iflavirus
model1<-glm(Normalized ~ Sex, data = fig1ifla)
summary(model1)
Anova(model1)
#=============================================
#for male
fig1iflam <- subset(fig1ifla, Sex=="Male")
fig1iflam

fig1iflam$Tissue <- as.factor(fig1iflam$Tissue)
fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Brain")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)

fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Mid_gut")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)


fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Testes")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)

fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Fat_bodies")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)

fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Salivary_gland")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)

fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Front_gut")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)


fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Hind_gut")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)

fig1iflam$Tissue <- relevel(fig1iflam$Tissue, ref= "Malpighian_tubules")
model1<-glm(Normalized ~ Tissue, data = fig1iflam)
summary(model1)
Anova(model1)

#------------------------------------------------------
#work with Iflavirus females

fig1iflaf <- subset(fig1ifla, Sex=="Female")
fig1iflaf

fig1iflaf$Tissue <- as.factor(fig1iflaf$Tissue)
fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Brain")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)

fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Mid_gut")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)


fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Ovary")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)

fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Fat_bodies")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)

fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Salivary_gland")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)

fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Front_gut")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)


fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Hind_gut")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)


fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Milk_glands")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)

fig1iflaf$Tissue <- relevel(fig1iflaf$Tissue, ref= "Malpighian_tubules")
model1<-glm(Normalized ~ Tissue, data = fig1iflaf)
summary(model1)
Anova(model1)

```

## statistical analysis for Negevirus

```{r}
#work for Negevirus

fig1nege <- subset(fig1, Virus=="Negevirus")
fig1nege

#difference between tissue regardsless the sex for Negevirus
model1<-glm(Normalized ~ Tissue, data = fig1nege)
summary(model1)
Anova(model1)

#difference between sex regardsless the tissues for Negevirus
model1<-glm(Normalized ~ Tissue, data = fig1nege)
summary(model1)
Anova(model1)

#for male
fig1negem <- subset(fig1nege, Sex=="Male")
fig1negem

fig1negem$Tissue <- as.factor(fig1negem$Tissue)
fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Brain")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)

fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Mid_gut")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)


fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Testes")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)

fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Fat_bodies")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)

fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Salivary_gland")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)

fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Front_gut")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)


fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Hind_gut")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)


fig1negem$Tissue <- relevel(fig1negem$Tissue, ref= "Malpighian_tubules")
model1<-glm(Normalized ~ Tissue, data = fig1negem)
summary(model1)
Anova(model1)
#------------------------------------------------------
#work with Iflavirus females

fig1negef <- subset(fig1nege, Sex=="Female")
fig1negef

fig1negef$Tissue <- as.factor(fig1negef$Tissue)
fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Brain")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)

fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Mid_gut")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)


fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Ovary")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)

fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Fat_bodies")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)

fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Salivary_gland")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)

fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Front_gut")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)


fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Hind_gut")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)

fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Milk_glands")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)

fig1negef$Tissue <- relevel(fig1negef$Tissue, ref= "Malpighian_tubules")
model1<-glm(Normalized ~ Tissue, data = fig1negef)
summary(model1)
Anova(model1)


```
